<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
	body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=QbzDKD2x6qHqkYqweGxBcwgGbnGodW4A"></script>
	<script type="text/javascript" src="../vendors/jquery/js/jquery.min.js"></script>
	<script src="../common/js/ff/ff.util.js"></script>
	<title>地图展示</title>
</head>
<body>
	<div id="allmap"></div>
</body>

<script type="text/javascript">
	// 百度地图API功能
	var lat = GetQueryString("lat");
	var lng = GetQueryString("lng");
    var map = new BMap.Map("allmap");

    var newaddr = "";
    var geoc = new BMap.Geocoder();   
    
    if (lat !== null && lat !== undefined && lat!== '') {
    	var point = new BMap.Point(lng,lat);
    	map.centerAndZoom(point,12);
    	map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    	var marker = new BMap.Marker(point);// 创建标注
	         map.addOverlay(marker);  // 将标注添加到地图中
	         map.panTo(point);     
	         marker.enableDragging(); //标注可拖拽
	         marker.addEventListener("dragend", function (e) {
	             var x = e.point.lng; //经度
	             var y = e.point.lat; //纬度
   	          	 ff.cache.set("newlat",y);
   	          	 ff.cache.set('newlng',x);
   	          	geoc.getLocation(e.point, function(rs){
   					var addComp = rs.addressComponents;
var detailaddr = addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber;
   					ff.cache.set('newaddr',detailaddr);
	   				ff.cache.set('newprovince',addComp.province);
   	   				ff.cache.set('newcity',addComp.city);	
   	   				ff.cache.set('newdistrict',addComp.district);
   				}); 
	         });
    } else {
    	  //浏览器定位
   	 var geolocation = new BMap.Geolocation();
   	 geolocation.getCurrentPosition(function (r) {
   	     if (this.getStatus() == BMAP_STATUS_SUCCESS) {
   	         map.centerAndZoom(r.point, 12); //定义地图等级，就是放大倍数
   	         map.enableScrollWheelZoom(true); //启用地图滚轮放大缩小  
   	         var marker = new BMap.Marker(r.point);// 创建标注
   	         map.addOverlay(marker);  // 将标注添加到地图中
   	         map.panTo(r.point);
   	         //alert('您的位置：' + r.point.lng + ',' + r.point.lat);     
   	         marker.enableDragging(); //标注可拖拽
   	         //marker.disableDragging();           // 不可拖拽
   	         // 开启事件监听
   	         marker.addEventListener("dragend", function (e) {
   	             var x = e.point.lng; //经度
   	             var y = e.point.lat; //纬度
   	             //alert("拖到的地点的经纬度：" + x + "，" + y);
   	          	 ff.cache.set("newlat",y);
   	          	 ff.cache.set('newlng',x);
   	          	 
   	          	geoc.getLocation(e.point, function(rs){
   	   				var addComp = rs.addressComponents;
   	   	var detailaddr = addComp.province + "" + addComp.city + "" + addComp.district + "" + addComp.street + "" + addComp.streetNumber;
   	   	//alert(addComp.province);
   	   				ff.cache.set("newaddr",detailaddr);
   	   				ff.cache.set("newprovince",addComp.province);
   	   				ff.cache.set("newcity",addComp.city);	
   	   				ff.cache.set("newdistrict",addComp.district);
   	   				
   	   			}); 
   	         });
   	     }
   	     else {
   	         alert('failed' + this.getStatus());
   	     }
   	 }, { enableHighAccuracy: true })
    }

    function GetQueryString(name)
    {
         var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
         var r = window.location.search.substr(1).match(reg);
         if(r!=null)return  unescape(r[2]); return null;
    }


</script>
</html>